package com.lianniu.web.tea.user.favour.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.tea.user.eva.service.impl.TeaUserEvaServiceImpl;
import com.lianniu.web.tea.user.favour.dao.TeaFavourDao;
import com.lianniu.web.tea.user.favour.model.TeaFavour;
import com.lianniu.web.tea.user.favour.service.ITeaUserFavourService;
import com.lianniu.web.util.UUIDUtil;

@Service
@Transactional
public class TeaUserFavourServiceImpl implements ITeaUserFavourService {

	private final static Logger logger = Logger.getLogger(TeaUserEvaServiceImpl.class);

	@Autowired
	private TeaFavourDao teaFavourDao;
	
	/**
	 * 点赞
	 */
	public BaseResult addFavour(TeaFavour teaFavour) {
		logger.info("TeaUserFavourServiceImpl addFavour start");
		String id = UUIDUtil.getUUID();
		teaFavour.setId(id);
		teaFavourDao.insert(teaFavour);
		logger.info("TeaUserFavourServiceImpl addFavour end");
		return BaseResult.success(teaFavour);
	}

	/**
	 * 取消点赞
	 */
	public BaseResult deleteFavour(String id) {
		logger.info("TeaUserFavourServiceImpl addFavour start");
		teaFavourDao.deleteByPrimaryKey(id);
		logger.info("TeaUserFavourServiceImpl addFavour end");
		return BaseResult.success();
	}

	@Override
	public BaseResult checkFavour(String productId, String userId) {
		logger.info("TeaUserFavourServiceImpl checkFavour start");
		Map param = new HashMap();
		param.put("productId", productId);
		param.put("userId", userId);
		String id = teaFavourDao.checkFavour(param);
		logger.info("TeaUserFavourServiceImpl checkFavour end");
		return BaseResult.success(id);
	}

}
